#include "point3d.h"

Point3D::Point3D()
{
    pPoss[0] = 0.0 ;
    pPoss[1] = 0.0 ;
    pPoss[2] = 0.0 ;
}

Point3D::Point3D( const Point3D& p )
{
    (*this) = p;
}

Point3D::Point3D( real x , real y , real z)
{
    pPoss[0]=x;
    pPoss[1]=y;
    pPoss[2]=z;
}

Point3D::Point3D( Vec3 poss )
{
    pPoss = poss;
}

Point3D &Point3D::operator=( const Point3D &p )
{
    pPoss = p.pPoss;
    return (*this);
}


bool Point3D::operator==(const Point3D& v) const
{
    double dx=pPoss[0]-v[0],  dy=pPoss[1]-v[1],  dz=pPoss[2]-v[2];
    return (dx*dx + dy*dy + dz*dz) < FEQ_EPS2;
}

bool Point3D::operator!=(const Point3D& v) const
{
    double dx=pPoss[0]-v[0],  dy=pPoss[1]-v[1],  dz=pPoss[2]-v[2];
    return (dx*dx + dy*dy + dz*dz) < FEQ_EPS2;
}

real Point3D::x( void ) const
{
    return pPoss[0];
}

real Point3D::y( void ) const
{
    return pPoss[1];
}

real Point3D::z( void ) const
{
    return pPoss[2];
}

void Point3D::x( real x )
{
    pPoss[0] = x;
}

void Point3D::y( real y )
{
    pPoss[1] = y;
}

void Point3D::z( real z )
{
    pPoss[2] = z;
}

Vec3 Point3D::toVec3( void ) const
{
    return pPoss;
}

Vec3 Point3D::toVector( void ) const
{
    return pPoss;
}

void Point3D::set( const Vec3 v )
{
    pPoss = v;
}

const Vec3 Point3D::operator-( Point3D p0 ) const
{
    real x = pPoss[0] - p0.x();
    real y = pPoss[1] - p0.y();
    real z = pPoss[2] - p0.z();
    return Vec3( x , y , z );
}

const Point3D Point3D::operator+( Vec3 v ) const
{
    real x = pPoss[0] + v[0];
    real y = pPoss[1] + v[1];
    real z = pPoss[2] + v[2];
    return Point3D( x , y , z );
}

Point3D Point3D::operator*(double t)
{
    return Point3D(x()*t , y()*t, z()*t);
}

void Point3D::operator+=( const Vec3& v )
{
    pPoss[0] += v[0];
    pPoss[1] += v[1];
    pPoss[2] += v[2];
}

real Point3D::max(real x , real y) const
{
    return (x>y) ? x : y ;
}

real Point3D::min(real x , real y) const
{
    return (x<y) ? x : y ;
}

Point3D  Point3D::min(const Point3D& p) const
{
    real x1 = min( x() , p.x() );
    real y1 = min( y() , p.y() );
    real z1 = min( z() , p.z() );
    return Point3D(x1,y1,z1);
}

Point3D  Point3D::max(const Point3D& p) const
{
    real x1 = max( x() , p.x() );
    real y1 = max( y() , p.y() );
    real z1 = max( z() , p.z() );
    return Point3D(x1,y1,z1);
}

Point3D Point3D::afineSum( real alpha , Point3D p ) const
{
    Vec3 vTmp = alpha*pPoss - (1-alpha)*p.pPoss ;
    return Point3D( vTmp );
}

Point3D Point3D::afineSum( Point3D p1, Point3D p2, float alpha)
{
    return Point3D((1-alpha)*p1.pPoss + alpha*p2.pPoss);
}
